package cn.wolfcode.web.controller;

import cn.wolfcode.query.JsonResult;
import cn.wolfcode.query.QueryObject;
import cn.wolfcode.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
	@Autowired
	private IPermissionService permissionService;

	@RequestMapping("/reload")
	@ResponseBody
	public JsonResult reload(){
		permissionService.reload();
		return new JsonResult();
	}

	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(Long id){
		if(id != null){
			permissionService.delete(id);
		}
		return new JsonResult();
	}

	@RequestMapping("/list")
	public String list(@ModelAttribute("qo") QueryObject qo, Model model){
		PageInfo pageInfo = permissionService.query(qo);
		model.addAttribute("pageInfo",pageInfo);
		return "/permission/list";
	}
}
